<template>
  <div class="app-page">
    <div class="left">
      <div class="list-box">
        <div class="c-header">
          <span>
            系统列表
            <span style="font-size: 14px;">(2个)</span>
          </span>
        </div>
        <div class="appList" style="height: 1048px;">
          <div class="list" :class="active === '01' ? 'active': ''" @click.stop="active = '01'">
            <div class="icon"></div>
            <span class="name">序列号追溯系统</span>
          </div>
          <div class="list" :class="active === '02' ? 'active': ''" @click.stop="active = '02'">
            <div class="icon"></div>
            <span class="name">金蝶云星空</span>
          </div>
        </div>
      </div>
    </div>
    <div class="right">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="110px">
      <el-form-item label="业务对象名称" prop="businessObjectName">
        <el-input
          v-model="queryParams.businessObjectName"
          placeholder="请输入业务对象名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['interfaceConfig:businessObject:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['interfaceConfig:businessObject:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['interfaceConfig:businessObject:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['interfaceConfig:businessObject:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="businessObjectList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center">
        <template slot-scope="scope">
          {{( queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}
        </template>
      </el-table-column>
      <el-table-column label="业务对象名称" align="center" prop="businessObjectName">
        <template #default="{row}">
          <span class="businessObjectName" @click.stop="handleUpdate(row)">{{row.businessObjectName}}</span>
        </template>
      </el-table-column>
      <el-table-column label="业务对象标识" align="center" prop="businessObjectFlag" />
      <el-table-column label="业务类型" align="center" prop="businessType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.business_type" :value="scope.row.businessType"/>
        </template>
      </el-table-column>
      <el-table-column label="是否有更新标识" align="center" prop="hasUpdateFlag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.has_update_flag" :value="scope.row.hasUpdateFlag"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['interfaceConfig:businessObject:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['interfaceConfig:businessObject:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </div>
  </div>
</template>

<script>
import { listBusinessObject, getBusinessObject, delBusinessObject, addBusinessObject, updateBusinessObject } from "@/api/interfaceConfig/businessObject/businessObject.js";

export default {
  name: "BusinessObject",
  dicts: ['business_type', 'has_update_flag'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 业务对象配置表格数据
      businessObjectList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        businessObjectName: null,
        sysPlatform: '01'
      },
      active: '01',
    };
  },
  watch: {
    'active': {
      immediate: false,
      handler(newVal, oldVal) {
        this.queryParams.sysPlatform = newVal
        this.getList()
      }
    }
  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 查询业务对象配置列表 */
    getList() {
      this.loading = true;
      listBusinessObject(this.queryParams).then(response => {
        this.businessObjectList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push( {
        path: '/businessObject/editBusinessObject',
        query: {
          sysPlatform: this.active
        }
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id || this.ids
      this.$router.push({
        path: '/businessObject/editBusinessObject',
        query: {
          businessId: id
        }
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateBusinessObject(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBusinessObject(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除业务对象配置编号为"' + ids + '"的数据项？').then(function() {
        return delBusinessObject(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('interfaceConfig/businessObject/export', {
        ...this.queryParams
      }, `businessObject_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>

.app-page{
  display: flex;
  flex-wrap: nowrap;
  margin-top: 20px;
  background-color: #fff;
  width: 100%;
  padding: 20px;
  min-height: calc(100vh - 140px);
  .left {
    flex-basis: 260px;
    .list-box {
      width: 260px;
      border: 1px solid #eeeeee;
      min-height: calc(100vh - 140px);
      .c-header{
        display: flex;
        -webkit-box-orient: horizontal;
        -webkit-box-direction: normal;
        -ms-flex-direction: row;
        flex-direction: row;
        -webkit-box-pack: justify;
        -ms-flex-pack: justify;
        justify-content: space-between;
        height: 60px;
        line-height: 60px;
        padding: 0 10px;
        cursor: pointer;
        font-size: 16px;
        overflow: hidden;
        padding-right: 15px;
        border-bottom: 1px solid #eee;
      }

      .appList {
        overflow-y: auto;
        .list {
          position: relative;
          font-size: 14px;
          height: 40px;
          line-height: 40px;
          overflow: hidden;
          -webkit-transition: color 0.3s;
          transition: color 0.3s;
          cursor: pointer;
          .name {
              display: block;
              padding-left: 15px;
              padding-right: 15px;
              white-space: nowrap;
              overflow: hidden;
              text-overflow: ellipsis;
          }
        }
      }
      .active {
        color: #1890ff;
        background-color: #e6f7ff;
        .icon {
            content: "";
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            border-left: 3px solid #1890ff;
        }
      }
    }
  }
  .right {
    width: calc(100% - 260px);
    padding-left: 20px;
    .businessObjectName {
      color: #0881ce;
      cursor: pointer;
      &:hover {
        text-decoration-line: underline;
      }
    }
  }
}
</style>
